home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2007 July & August
/
PCWorld_2007-07-08_cd.bin
/
komunikace
/
ie7pro
/
IE7proSetup.exe
/
{app}
/
plugins
/
accuweather
/
plugin.js
< prev
Wrap
Text File
|
2007-04-23
|
9KB
|
224 lines
// ==UserScript==
// @name Accu Weather
// @namespace http://iescripts.org
// @description Display the local weather in the statusbar, Copy from Windows vista accu weather gadgets
// @statussize 180
// ==/UserScript==
(function()
{
var plugin = PRO_plugin(@name);
var currentWeather = "";
var currentIcon = "ie7pro://pluginpath/images/01.png";
var currentTip = "";
var WeatherUnits;
var CurrentLocation;
var CurrentConditions;
var CurrentImages;
var CurrentForecasts;
var CurrentWatches;
var CurrentLinks;
var ErrorString="";
var DataComplete=false;
plugin.registerContextMenu("Set Location", menuSetLocation);
plugin.ontabcreate = handleTabCreate;
plugin.onpopupclose = handlePopupClose;
var reqObj = new Object();
reqObj.request = function(callback, cookie, url, userAgent, lastModify,qtype) {
var req;
req = PRO_xmlhttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) {// completed
if (req.status < 400) {// only if "OK"
try {
callback(req, cookie);
} catch(err) {
}
} else {
// PRO_log("There was a problem loading data :\n" + req.status+ "/" + req.statusText);
}
setTimeout(function() {req.forceClean();req = null;}, 1000);
}
}
try {
req.open(qtype, url);
req.setRequestHeader( "User-Agent", userAgent);
if(lastModify.length > 0)
req.setRequestHeader( "If-Modified-Since", lastModify);
req.send(null);
} catch(err){
}
return req;
}
UpdateWeather();
setInterval(UpdateWeather, 1000*60*30 );
function menuSetLocation(cookie,url) {
plugin.popupWindow("ie7pro://pluginpath/findLocation.html",500,400,cookie);
}
function handleTabCreate(cookie) {
plugin.setStatusInfo(currentIcon, currentWeather, currentTip);
}
function handlePopupClose(cookie) {
UpdateWeather();
}
function processWeatherData(req, cookie) {
parseData(req.responseXML.documentElement);
}
function UpdateWeather() {
var mylocation=PRO_getValue("weather_Location","10001");
var mymetric=PRO_getValue("weather_Unit","metric");
var met = 1;
if(mymetric == "english") met = 0;
var queryurl = "http://vwidget.accuweather.com/widget/vista1/weather_data_v2.asp?location=" + mylocation + "&metric=" + met;
reqObj.request(processWeatherData, "", queryurl, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; Alexa Toolbar)", "Thu, 26 Aug 2002 08:24:16 GMT","GET");
}
function Images(xmlNode) {
this.radar=xmlNode.getElementsByTagName('radar').item(0).firstChild.data;
}
function Units(xmlNode) {
this.tempUnit=xmlNode.getAttribute('temp');
this.speedUnit=xmlNode.getAttribute('speed');
this.distUnit=xmlNode.getAttribute('dist');
this.presUnit=xmlNode.getAttribute('pres');
this.precUnit=xmlNode.getAttribute('prec');
}
function Watches(xmlNode) {
this.zone=xmlNode.getAttribute('zone');
this.county=xmlNode.getAttribute('county');
this.isactive=xmlNode.getAttribute('isactive');
if (xmlNode.getElementsByTagName('url').item(0).firstChild!=null) {
this.url=xmlNode.getElementsByTagName('url').item(0).firstChild.data;
} else {
this.url="";
}
}
function Location(xmlNode) {
this.city=xmlNode.getAttribute('city');
this.state=xmlNode.getAttribute('state');
}
function Conditions(xmlNode) {
this.url=xmlNode.getElementsByTagName('url').item(0).firstChild.data;
tempNode=xmlNode.getElementsByTagName('wxc').item(0);
this.temperature=tempNode.getAttribute('temp');
this.realFeel=tempNode.getAttribute('rft');
this.humidity=tempNode.getAttribute('hum');
this.text=tempNode.getAttribute('text');
this.icon=tempNode.getAttribute('icon');
this.windGust=tempNode.getAttribute('wgus');
this.windSpeed=tempNode.getAttribute('wspd');
this.windDir=tempNode.getAttribute('wdir');
this.visibility=tempNode.getAttribute('vis');
this.precip=tempNode.getAttribute('prec');
this.uvindex=tempNode.getAttribute('uvi');
this.uvtext=tempNode.getAttribute('uvt');
this.radarUrl=xmlNode.getElementsByTagName('radurl').item(0).firstChild.data;
}
function Links(xmlNode) {
this.promo1Link=xmlNode.getElementsByTagName('promo1').item(0).getAttribute('url');
this.promo1Name=xmlNode.getElementsByTagName('promo1').item(0).getAttribute('name');
this.homeLink=xmlNode.getElementsByTagName('home').item(0).getAttribute('url');
}
function Forecasts(xmlNode) {
tempNodes=xmlNode.getElementsByTagName('day');
tempArray=new Array(tempNodes.length);
for (count=0;count<tempNodes.length;count++) {
tempArray[count]=new ForecastDay(tempNodes[count]);
}
this.forecastArray=tempArray;
}
function ForecastDay(xmlNode) {
this.dayNumber=xmlNode.getAttribute('number');
this.date=xmlNode.getAttribute('date');
this.weekDay=xmlNode.getAttribute('wday');
switch (this.weekDay) {
case "Monday" : this.shortWeekDay="Mon";break;
case "Tuesday" : this.shortWeekDay="Tue";break;
case "Wednesday" : this.shortWeekDay="Wed";break;
case "Thursday" : this.shortWeekDay="Thu";break;
case "Friday" : this.shortWeekDay="Fri";break;
case "Saturday" : this.shortWeekDay="Sat";break;
case "Sunday" : this.shortWeekDay="Sun";break;
}
this.url=xmlNode.getElementsByTagName('url').item(0).firstChild.data;
//Daytime forecast data
this.daytimeTextShort=xmlNode.getElementsByTagName('./daytime/txtshort').item(0).firstChild.data;
this.daytimeTextLong=xmlNode.getElementsByTagName('./daytime/txtlong').item(0).firstChild.data;
this.daytimeIcon=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('icon');
this.daytimeHigh=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('htmp');
this.daytimeRealFeelHigh=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('rfh');
this.daytimeWindSpeed=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('wspd');
this.daytimeWindDirection=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('wdir');
this.daytimeWindGust=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('wgus');
this.daytimeMaxUV=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('mxuv');
this.daytimeRain=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('rain');
this.daytimeSnow=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('snow');
this.daytimePrecip=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('prec');
//Nighttime forecast data
this.nighttimeTextShort=xmlNode.getElementsByTagName('./nighttime/txtshort').item(0).firstChild.data;
this.nighttimeTextLong=xmlNode.getElementsByTagName('./nighttime/txtlong').item(0).firstChild.data;
this.nighttimeIcon=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('icon');
this.nighttimeLow=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('ltmp');
this.nighttimeRealFeelLow=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('rfl');
this.nighttimeWindSpeed=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('wspd');
this.nighttimeWindDirection=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('wdir');
this.nighttimeWindGust=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('wgus');
this.nighttimeRain=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('rain');
this.nighttimeSnow=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('snow');
this.nighttimePrecip=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('prec');
}
function parseData(xmlData) {
try {
CurrentLocation=new Location(xmlData.getElementsByTagName("./local").item(0));
WeatherUnits=new Units(xmlData.getElementsByTagName("./units").item(0));
CurrentConditions=new Conditions(xmlData.getElementsByTagName("./currentconditions").item(0));
CurrentImages=new Images(xmlData.getElementsByTagName("./images").item(0));
CurrentForecasts=new Forecasts(xmlData.getElementsByTagName("./forecast").item(0));
CurrentWatches=new Watches(xmlData.getElementsByTagName("./watchwarnareas").item(0));
CurrentLinks=new Links(xmlData.getElementsByTagName("./links").item(0));
DataComplete=true;
var mymetric=PRO_getValue("weather_Unit","metric");
if(mymetric == "metric" )
met = "Γäâ";
else
met = "Γäë";
currentWeather = "Now: " + CurrentConditions.text + "," + CurrentConditions.temperature + met + "(" + CurrentLocation.city + ")";
currentIcon = "ie7pro://pluginpath/images/" + CurrentConditions.icon + ".png";
currentTip = '<B>' + CurrentLocation.city + ' Weather Forecast</B><br>';
for(i=0;i<5;i++) {
currentTip += CurrentForecasts.forecastArray[i].date + " " + CurrentForecasts.forecastArray[i].weekDay + " Hi:" + CurrentForecasts.forecastArray[i].daytimeHigh + met + " Lo:" + CurrentForecasts.forecastArray[i].nighttimeLow +met + " " + CurrentForecasts.forecastArray[i].daytimeTextShort + "<br>";
}
currentTip += " ";
plugin.setStatusInfo(currentIcon, currentWeather,currentTip)
} catch (e) {
}
}
}
)();